package com.zhong.gang.applib.ui.preview;

import android.content.Context;
import android.content.Intent;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

import com.zhong.gang.applib.R;
import com.zhong.gang.applib.base.act.ActBase;
import com.zhong.gang.applib.databinding.LayoutViewpagerBinding;
import com.zhong.gang.applib.utils.ViewPagerAdapter;

import java.util.ArrayList;
import java.util.List;

public class PreviewAct extends ActBase<LayoutViewpagerBinding> {
    private List<Fragment> list = new ArrayList<>();
    private static final String DATA ="DATA",NUMBER ="NUMBER";
    public static final void openAct(Context context,ArrayList<String> data, int number){
        Intent intent = new Intent(context,PreviewAct.class);
        intent.putStringArrayListExtra(DATA,data);
        intent.putExtra(NUMBER,number);
        context.startActivity(intent);
    }
    @Override
    public int LayoutRes() {
        return R.layout.layout_viewpager;
    }

    @NonNull
    @Override
    public String CreateTitle() {
        return "预览";
    }

    @Override
    public void initView() {
        getTitleBar().setVisibility(View.GONE);

        List<String> data = getIntent().getStringArrayListExtra(DATA);
        if (data == null)
            return;
        list.clear();
        for (int n = 0 ;n <data.size();n++){
            list.add(PerviewFragment.newIntent(data.get(n),n+1,data.size()));
        }
        bind.viewPager.setOffscreenPageLimit(list.size());
        bind.viewPager.setAdapter(new ViewPagerAdapter(getSupportFragmentManager(),list));
        bind.viewPager.setCurrentItem(getIntent().getIntExtra(NUMBER,0));
    }
}
